package com.stox.ui.javafx.charting.model.uiunit;

import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;

import com.stox.ui.javafx.charting.model.plot.NumberPlot;
import com.stox.ui.javafx.charting.widget.Chart;

public class NumberUiUnit extends AbstractUiUnit<Number, 
																	Chart<NumberPlot>, 
																	NumberUiUnit, 
																	NumberPlot> {

	private double y;
	
	public NumberUiUnit(Number model, NumberPlot plot, int index) {
		super(model, plot, index);
	}
	
	@Override
	public void update() {
		super.update();		
		getPlot().getColorStrategy().apply(this);
		y = height(getModel().doubleValue());
	}
	
	@Override
	public void paint() {
		Canvas canvas = getPlot().getChart().getCanvas();
		GraphicsContext gc = canvas.getGraphicsContext2D();
		gc.setFill(getColor());
		double w = width*3/4;
		gc.fillRoundRect(x+width/8, y, w, canvas.getLayoutY() + canvas.getHeight() - y, w, w);
	}

	public double getY() {
		return y;
	}

	public void setY(double y) {
		this.y = y;
	}
	
}
